package com.jpa.lgt.core.common;

import lombok.Data;

/**
 * @author wangweizhi
 * @date 2017/12/13
 */
@Data
public class Result<T> {

    public static final int SUCCESS = 0;
    public static final int FAILURE = -1;
    private int code = FAILURE;
    private String errMsg = "";
    private T data;

    public static Result genSuccessResult() {
        Result result = new Result();
        result.code = SUCCESS;
        result.errMsg = "ok";
        return result;
    }

    public static Result genSuccessResult(Object obj) {
        Result result = new Result();
        result.code = SUCCESS;
        result.errMsg = "ok";
        result.data = obj;
        return result;
    }

    public static Result genFailedResult(String errMsg, Object obj) {
        Result result = new Result();
        result.code = FAILURE;
        result.errMsg = errMsg;
        result.data = obj;
        return result;
    }

    public static Result genFailedResult(Integer code, String errMsg, Object obj) {
        Result result = new Result();
        result.code = code;
        result.errMsg = errMsg;
        result.data = obj;
        return result;
    }
}
